package com.suoluo.zenapp.common.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.core.io.Resource;

public final class SystemConfigHolder {

	private static SystemConfig configHolder;

	public static SystemConfig createConfigHolder(Resource springResource)
			throws Exception {

		Properties p = loadProperties(springResource.getFile());
		configHolder = new SystemConfigImpl(p);
		return configHolder;
	}

	/**
	 * 获取图片的保存路径
	 * 
	 * @return
	 */
	public static String getImgPath() {
		return configHolder.getString("img.path",
				"http://192.168.1.106:8080/zenapp/upload/images/");
	}
	/**
	 * 数据库查询描述信息的长度
	 * @return
	 */
	public static int getDescLength(){
		return configHolder.getInt("desc_length", 150);
	}
	
	public static Properties loadProperties(File f) {
		Properties props = new Properties();
		if (f == null || false == f.isFile()) {
			return props;
		}
		InputStream fis = null;
		try {
			fis = new FileInputStream(f);
			props.load(fis);
		} catch (Exception e) {

		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return props;
	}
	
	/**
	 * 获取mini小图片的前缀
	 */
	public static String getMiniImgPreffix(){
		return configHolder.getString("mini_img_preffix","mini");
	}
	
	public static int getSystemImgBlockWidth(){
		return configHolder.getInt("isc_system_image_block_width",235);
	}
	
	public static int getSystemImgBlockHeight(){
		return configHolder.getInt("isc_system_image_block_height",180);
	}
}
